<?php
class runtime
{ 
    var $StartTime = 0; 
    var $StopTime = 0; 
 
    function get_microtime() 
    { 
        list($usec, $sec) = explode(' ', microtime()); 
        return ((float)$usec + (float)$sec); 
    } 
 
    function start() 
    { 
        $this->StartTime = $this->get_microtime(); 
    } 
 
    function stop() 
    { 
        $this->StopTime = $this->get_microtime(); 
    } 
 
    function spent() 
    { 
        //return round(($this->StopTime - $this->StartTime) * 1000, 1);
	return ($this->StopTime - $this->StartTime) * 1000;
    } 
 
}

function apply( &$var, $list ) {
	$functions = split( '\|', $list );

	foreach( $functions as $change ) {
		$var = $change( $var );
	}
}

class StrApply0 {
	var $str = '';

	function __construct($s) {
		$this->str = $s;
	}

	function trim() {
		$this->str = trim($this->str);
		return $this;
	}

	function strtolower() {
		$this->str = strtolower($this->str);
		return $this;
	}
	
	function ucwords() {
		$this->str = ucwords($this->str);
		return $this;
	}

	function strip_tags() {
		$this->str = strip_tags($this->str);
		return $this;
	}

	function toString() {
		return $this->str;
	}
}

$str = "          heLLO HoW ARE you?        ";
$rte = new runtime();
$rte->start();
apply($str, 'trim|strtolower|ucwords|strip_tags');
echo "'" . $str . "'";
$rte->stop();
echo "\r\nFunction 'apply' costs " . $rte->spent() . "ms\r\n";

$str = "          heLLO HoW ARE you?        ";
$rte = new runtime();
$rte->start();
$sto = new StrApply0($str);
$str = $sto->trim()->strtolower()->ucwords()->strip_tags()->toString();
echo "'" . $str . "'";
$rte->stop();
echo "\r\nClass 'apply' costs " . $rte->spent() . "ms\r\n";


?>
